

package org.argeproje.resim;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;

import org.argeproje.resim.ui.model.ShapesDiagram;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IPathEditorInput;
import org.eclipse.ui.IPersistableElement;

public class ShapesEditorInput implements IPathEditorInput {

	private IPath path;

	public ShapesEditorInput(IPath path) {
		this.path = path;
	}

	public boolean exists() {
		return path.toFile().exists();
	}

	public ImageDescriptor getImageDescriptor() {
		return ShapesPlugin.imageDescriptorFromPlugin(ShapesPlugin.PLUGIN_ID,
				"shapes.gif");
	}

	public String getName() {
		return path.toString();
	}

	public IPersistableElement getPersistable() {
		return null;
	}

	public String getToolTipText() {
		return path.toString();
	}

	public Object getAdapter(Class adapter) {
		return null;
	}

	public int hashCode() {
		return path.hashCode();
	}

	public ShapesDiagram getShapesDiagram() {
		FileInputStream fis;
		try {
			fis = new FileInputStream(path.toFile());
			ObjectInputStream ois = new ObjectInputStream(fis);
			return (ShapesDiagram)ois.readObject();
			//return new ShapesDiagram();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public IPath getPath() {
		return path;
	}

	public boolean equals(Object obj) {
		return obj.equals(this);
	}

}
